#include <chrono>
#include <iostream>

#include "threadpool.h"
using namespace std;
void Test1() {
  ThreadPool pool(4);
  pool.AddTask([]() {
    std::this_thread::sleep_for(std::chrono::seconds(2));
    cout << "task1" << endl;
  });
  pool.AddTask([]() {
    std::this_thread::sleep_for(std::chrono::seconds(2));
    cout << "task2" << endl;
  });
  pool.AddTask([]() {
    std::this_thread::sleep_for(std::chrono::seconds(2));
    cout << "task3" << endl;
  });
  pool.AddTask([]() {
    std::this_thread::sleep_for(std::chrono::seconds(5));
    cout << "task4" << endl;
  });
  pool.AddTask([]() {
    cout << "task5" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  pool.AddTask([]() {
    cout << "task6" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  pool.AddTask([]() {
    cout << "task7" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  pool.AddTask([]() {
    cout << "task8" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  pool.AddTask([]() {
    cout << "task9" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  pool.AddTask([]() {
    cout << "task10" << endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
  });
  cout << "任务提交完毕!" << endl;
}
void Test2() {
  ThreadPool pool;
  int a = 10;
  std::future<int> fut = pool.AddTask(
      [a](int b) -> int {
        std::this_thread::sleep_for(std::chrono::seconds(3));
        return a + b;
      },
      5);
  cout << "任务提交完毕!" << endl;
  cout << fut.get() << endl;
}
int main() {
  // Test1();
  Test2();
  return 0;
}